﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web.UI.WebControls;
using BLL;

namespace UI.ModEmployee
{
    public partial class DefRewardsTypeList : System.Web.UI.Page
    {
        DefDicBiz defineDictionary = new DefDicBiz();
        string tableName = "Admin_Rewards_Type";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnAdd.Attributes.Add("onclick", "javascript:ShowLink('DefRewardsTypeAdd.aspx',600,480);");
                BindData("Y");
            }
        }

        protected void btnShowOpen_Click(object sender, EventArgs e)
        {
            BindData("Y");
        }

        protected void btnShowClose_Click(object sender, EventArgs e)
        {
            BindData("N");
        }
        private void BindData(string statu)
        {
            if (statu == "N")
            {
                btnClose.Visible = false;
                btnOpen.Visible = true;
            }
            else
            {
                btnClose.Visible = true;
                btnOpen.Visible = false;
            }
            DataTable dt = defineDictionary.GetLists(tableName, statu);
            gvList.DataSource = dt;
            gvList.DataBind();

        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            for (int i = 0; i <= gvList.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)gvList.Rows[i].FindControl("CheckBox1");
                if (cbox.Checked == true)
                {
                    //
                    SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
                    sdList.Add("ID", gvList.DataKeys[i].Value.ToString());
                    sdList.Add("Statu", "N");
                    defineDictionary.Update(tableName, sdList);
                }
            }
            BindData("Y");
        }

        protected void btnOpen_Click(object sender, EventArgs e)
        {
            for (int i = 0; i <= gvList.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)gvList.Rows[i].FindControl("CheckBox1");
                if (cbox.Checked == true)
                {
                    //
                    SortedDictionary<string, string> sdList = new SortedDictionary<string, string>();
                    sdList.Add("ID", gvList.DataKeys[i].Value.ToString());
                    sdList.Add("Statu", "Y");
                    defineDictionary.Update(tableName, sdList);
                }
            }
            BindData("N");
        }



        protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[1].Visible = false;
            }
        }
    }
}